import React, { useState } from 'react';
import {
  DesktopOutlined,
  FileOutlined,
  PieChartOutlined,
  TeamOutlined,
  UserOutlined,
} from '@ant-design/icons';
import type { MenuProps } from 'antd';
import { Breadcrumb, Layout, Menu, theme } from 'antd';
import { CSSProperties } from 'react';
import { useNavigate, Outlet } from 'react-router-dom'
// import router from '@/router'

const { Header, Content, Footer, Sider } = Layout;

type MenuItem = Required<MenuProps>['items'][number];

function getItem(
  label: React.ReactNode,
  key: React.Key,
  icon?: React.ReactNode,
  children?: MenuItem[],
): MenuItem {
  return {
    key,
    icon,
    children,
    label,
  } as MenuItem;
}

const items: MenuItem[] = [
  getItem('栏目 1', '/page1', <PieChartOutlined />),
  getItem('栏目 2', '/page2', <DesktopOutlined />),
  getItem('User', 'sub1', <UserOutlined />, [
    getItem('Tom', '3'),
    getItem('Bill', '4'),
    getItem('Alex', '5'),
  ]),
  getItem('Team', 'sub2', <TeamOutlined />, [getItem('Team 1', '6'), getItem('Team 2', '8')]),
  getItem('Files', '9', <FileOutlined />),
];


const View: React.FC = () => {
  const [collapsed, setCollapsed] = useState(false);
  const navigetto = useNavigate()
  const {
    token: { colorBgContainer, borderRadiusLG },
  } = theme.useToken();

  const menuClick = (e: { key: string }) => {
    console.log(e.key, 'e')
    // 点击跳转到对应路由 编程式导航跳转
    navigetto(e.key)
  }
  // 使用类型推断（不显式声明类型）：
  // TypeScript 可以自动推断对象字面量的类型：
  // const demoLogoVertical = {
  //   height: '32px',
  //   margin: '15px',
  //   marginBottom: '5px',
  //   backgroundColor: 'rgba(255,255,255,0.3)'
  // }

  // 内联样式写法
  // const demoLogoVertical: {
  //   height: string,
  //   margin: string,
  //   marginBottom: string,
  //   backgroundColor: string
  // } = {
  //   height: '32px',
  //   margin: '15px',
  //   marginBottom: '5px',
  //   backgroundColor: 'rgba(255,255,255,0.3)'
  // }

  // CSSProperties 推荐使用这种
  // 对于 React 的样式对象，通常使用 React.CSSProperties 类型，这是 React 提供的内置类型，包含了所有有效的 CSS 属性及其对应的值类型。-
  const demoLogoVertical: CSSProperties = {
    height: '32px',
    margin: '15px',
    marginBottom: '5px',
    backgroundColor: 'rgba(255,255,255,0.3)'
  };


  return (
    <Layout style={{ minHeight: '100vh' }}>
      {/* 左边侧边栏 */}
      <Sider collapsible collapsed={collapsed} onCollapse={(value) => setCollapsed(value)}>
        <div style={demoLogoVertical} />
        <Menu onClick={menuClick} theme="dark" defaultSelectedKeys={['1']} mode="inline" items={items} />
      </Sider>
      {/* 右边内容 */}
      <Layout>
        {/* 右边头部 */}
        <Header style={{ paddingLeft: 16, background: colorBgContainer }}>
          <Breadcrumb style={{ lineHeight: '64px' }} items={[{ title: 'User' }, { title: 'Bill' }]} />
        </Header>
        {/* 右边内容-白色底盒子 */}
        <Content style={{
          margin: '16px', padding: 24,
          minHeight: 360,
          background: '#ccc',
          borderRadius: borderRadiusLG,
        }} className=''>
          {/* 窗口部分 */}
          <Outlet />
        </Content>
        {/* 右边底部 */}
        <Footer style={{ textAlign: 'center', padding: 0, lineHeight: '30px' }}>
          Ant Design ©{new Date().getFullYear()} Created by Ant UED
        </Footer>
      </Layout>
    </Layout>
  );
};

export default View;